
module Schnell
  # This class is the means of accessing an image on a page.
  # Normally a user would not need to create this object as it is returned by the Schnell::Container#image method
  #
  # many of the methods available to this object are inherited from the Element class
  #
  class Image < Element
    ELEMENT_TYPE = "img"
    
    # used internally to locate the image
    def locate
      if @how == :src
        @element = @page.findElementByXPath("//#{self.class::ELEMENT_TYPE}[@src='#{@what}']")
      elsif @how == :alt
        @element = @page.findElementByXPath("//#{self.class::ELEMENT_TYPE}[@alt='#{@what}']")
      else
        super()
      end
    rescue
      @element = nil
    end
    
    private :locate
    
    # return the alt of the element
    def_wrap_guard :alt # input elements only  
    # return the href of the link
    def_wrap_guard :src
  end
end
